package com.example.yiqiuser.service.impl;


import com.example.yiqiuser.dao.TScenicTicketDao;
import com.example.yiqiuser.entity.TScenicTicket;
import com.example.yiqiuser.service.TScenicTicketService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 景区门票表(TScenicTicket)表服务实现类
 *
 * @author makejava
 * @since 2023-03-30 16:00:39
 */
@Service
public class TScenicTicketServiceImpl implements TScenicTicketService {
    @Resource
    private TScenicTicketDao tScenicTicketDao;

    @Override
    public PageInfo<TScenicTicket> queryParam(Page<TScenicTicket> page) {
        PageHelper.startPage(page.getPageNo(),page.getPageSize());
        return new PageInfo<>(tScenicTicketDao.queryByParam(page.getData()));
    }

    @Override
    public List<TScenicTicket> queryAll() {
        TScenicTicket tScenicTicket = new TScenicTicket();

        return tScenicTicketDao.queryByParam(tScenicTicket);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TScenicTicket queryById(Integer id) {
        List<TScenicTicket> tScenicTickets = tScenicTicketDao.queryById(id);
        if (tScenicTickets!=null&&tScenicTickets.size()>0){
            return tScenicTickets.get(0);
        }
        return null;
    }

    /**
     * 新增数据
     *
     * @param tScenicTicket 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(TScenicTicket tScenicTicket) {
        return tScenicTicketDao.insert(tScenicTicket);
    }

    /**
     * 修改数据
     *
     * @param tScenicTicket 实例对象
     * @return 实例对象
     */
    @Override
    public int update(TScenicTicket tScenicTicket) {
        try {
            tScenicTicketDao.update(tScenicTicket);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer id) {
        return tScenicTicketDao.deleteById(id);
    }
}
